package com.cloud.recyclervieweffectdemo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.cloud.recyclervieweffectdemo.adapter.EffectAdapter
import com.cloud.recyclervieweffectdemo.bean.EffectBean

class MainActivity : AppCompatActivity() {
    private var adapter:EffectAdapter ?= null
    private var dataList:MutableList<EffectBean> ?= null
    private val rvEffect:RecyclerView by lazy { findViewById(R.id.rv_effect) }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
       initData()
       initAdapter()
    }

    /**
     * 初始化数据
     */
    private fun initData() {
        val effectBean = EffectBean()
        dataList = ArrayList()
        for(i in 1..15){
            effectBean.name = "小麦"
            effectBean.avatar = "222"
            dataList?.add(effectBean)
        }
    }

    /**
     * 初始化适配器
     */
    private fun initAdapter() {
        adapter = dataList?.let { EffectAdapter(it) }
        rvEffect.layoutManager = LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false)
        rvEffect.adapter = adapter
    }
}